<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/login.css">
    <link rel="stylesheet" href="css/font-awesome-4.7.0/css/font-awesome.css">
</head>

<body>
    <h1><img src="img/material/logo.png" alt=""></h1>
    <div class="main">
        <div class="formDiv">
            <div class="btnLeft bg">
                <p>用户名登录</p>
            </div>
            <div class="btnRight">
                <p>二维码登录</p>
            </div>
            <form id="pubForm">
                <input type="text" name="text" id="username" placeholder="请输入手机号">
                <p class="op"></p>
                <p class="pass_eye">
                    <span class="fa fa-eye"></span>
                    <input type="password" name="password" id="password" placeholder="请输入密码">
                </p>
                <p class="op2"></p>
                <div class="check">
                    <input type="checkbox" name="checkbox" id="checkbox">
                    <label for="checkbox">记住密码</label>
                </div>
                <a href="javascript:void(0)">忘记密码?</a>
                <input type="submit" name="log_btn" id="log_btn" value="登录">
                <input type="button" name="reg_btn" id="reg_btn" value="注册">
            </form>
            <!-- 二维码 -->
            <img src="img/material/erweima.png" alt="">
        </div>
    </div>
    <!-- footer -->
    <footer>
        <p>量子矩阵公司 版权所有 Copyright © 2018-2019 QUTO Corporation, All Rights Reserved</p>
    </footer>
</body>
<script src="js/jquery-3.4.1.js"></script>
<script src="js/ipUrl.js"></script>
<script src="js/jquery.validate.js"></script>
<script src="js/messages_zh.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/hideShowPassword-master/hideShowPassword.js"></script>
<script>

    // 查看 密码 小眼睛
     var onOff = true;
    $('#password').on('input propertychange', function () {
        if ($('#password').val() == '') {
            $('.pass_eye span').css('display', 'none');
        } else {
            $('.pass_eye span').css('display', 'block');
        }
    });
	$('.pass_eye span').click(function () {
		if (onOff) {
			$('#password').showPassword();
			onOff = false;
		} else {
			$('#password').hidePassword();
			onOff = true;
		}
	});
    $(function () {
        $('.btnLeft').on('click', function () {
            $('form').css('display', 'block');
            $('.formDiv img').css('display', 'none');
            $(this).addClass('bg').siblings().removeClass('bg');
        });
        $('.btnRight').on('click', function () {
            $('form').css('display', 'none');
            $('.formDiv img').css('display', 'inline-block');
            $(this).addClass('bg').siblings().removeClass('bg');
        });
    });
    // $('#log_btn').click(function () {
    //     window.location.href = 'public-sidebar-header.html';
    // });

    // 点击登陆按钮跳转到注册页面
    $('#reg_btn').click(function () {
        window.location.href = 'register.html';
    });

    // 判断input框输入内容格式是否符合
    $('#pubForm').validate({
        rules: {
            text: {
                required: true,
                minlength: 3
            },
            password: {
                required: true,
                minlength: 3,
                maxlength: 15
            }
        },
        messages: {
            text: {
                required: '请输入手机号/用户名'
            },
            password: {
                required: '请输入密码',
                minlength: '请输入6-15字符',
                maxlength: '请输入6-15字符'
            }
        },
        submitHandler: function () {
            $.ajax({
                url: loginURL + ':9999/oaSystem/login',
                type:'post',
                data:{
                    username:$('#username').val(),
                    password:$('#password').val()
                },
				// dataType:'json',
                success: function(data){
                    var dataJson = JSON.parse(data);
					// if(dataJson.code == 100){
						alert("登陆成功!");
						localStorage.setItem('jsonId',data);//将登录时获取的数据存入
						window.location.href = 'public-sidebar-header.html';
					// }
                    // console.log(data);
                    // console.log(username);
                },
                error:function(xhr,errorType){
                    console.log(errorType);
                }
            });
        }

    });
    // 格式不对，弹出错误
    $("#username").blur(function () {
        // console.log($('#username-error').html())
        $('.op').html($('#username-error').html());
    })
    $("#password").blur(function () {
        // console.log($('#password-error').html())
        $('.op2').html($('#password-error').html());
    })
</script>

</html>